#ifndef _ENTITY_
#define _ENTITY_

#include "sprite.h"
#include "physics.h"

class Entity
{
private:
	Sprite spr;
	PhysicsObject * phys;
	
public:
	bool Visible;
	bool Enabled;
	Entity()
	{
		spr.SetPosition(b2Vec2_zero);
		spr.Visible = Visible = true;
	}
	Entity(bool fixedRotation)
	{
		spr.SetPosition(b2Vec2_zero);
		spr.Visible = Visible = true;
	}
	bool LoadData(char * Folder,bool rotationFixed = false)
	{
		phys = new PhysicsObject(rotationFixed);
		char Data[MAX_PATH];
		strcpy(Data,Folder);
		strcat(Data,"\\sprite.zbs");
		bool result = spr.LoadTexture(Data);
		Data[strlen(Data) - 11] = '\0';
		strcat(Data,"\\physics.zbp");
		bool result2 = phys->LoadPhysics(Data);
		Data[strlen(Data) - 12] = '\0';
		return result && result2;
	}
	void SetPosition(b2Vec2 newpos,bool RemoveVelocities = false)
	{
		spr.SetPosition(newpos);
		phys->SetPosition(newpos);
		if (RemoveVelocities)
		{
			phys->SetAngularV(0);
			phys->SetLinearV(b2Vec2_zero);
		}
	}
	b2Vec2 GetPosition()
	{
		return phys->GetPosition();
	}
	void SetAngle(float32 newangle)
	{
		spr.SetAngle(newangle);
		phys->SetAngle(newangle);
	}

	float32 GetAngle()
	{
		return RadianToSexagesimal(phys->GetAngle());
	}
	void Draw()
	{
		if (!Enabled)
		{
			phys->Freeze();
			return;
		}
		spr.SetAngle(-phys->GetAngle());
		spr.Visible = Visible;
		spr.SetPosition(phys->GetPosition());
		spr.Draw();
	}
	PhysicsObject * GetPhysics()
	{
		return phys;
	}
	Sprite * GetSprite()
	{
		return &spr;
	}
};

#endif
